//
//  JSMDreamCitySpecialDetailTableViewCell.m
//  TakeYouTourTogether
//
//  Created by king on 15/12/2.
//  Copyright © 2015年 king. All rights reserved.
//

#import "JSMDreamCitySpecialDetailTableViewCell.h"

@implementation JSMDreamCitySpecialDetailTableViewCell

#pragma mark - Method 自定义初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createTableViewCell];
    }
    return self;
}
#pragma mark - Method 创建cell控件
- (void)createTableViewCell {
    self.myImageView = [[UIImageView alloc] init];
    self.myImageView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.myImageView];
    self.myLabel = [[UILabel alloc] init];
    self.myLabel.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.myLabel];
    // 设置myLabel的行数
    self.myLabel.numberOfLines = 0;
    // 设置字体大小
    self.myLabel.font = [UIFont systemFontOfSize:16];
}
#pragma mark - Method 设置控件frame
- (void)layoutSubviews {
    [super layoutSubviews];
    // 最后走得一个方法, 在这个方法里, 属性已经被赋好值了
    // 也是根据图片的尺寸, 计算高度
//    CGFloat picHeight = self.myImageView.image.size.height * self.contentView.frame.size.width / self.myImageView.image.size.width;
    self.myImageView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 333*ALL_EDITION_HEIGHT);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:16], NSFontAttributeName, nil];
    // 根据文本字体大小来计算文本的cell高度
    // 第一个参数: 文字显示的最大尺寸范围(375, 0)
    CGRect rect = [self.myLabel.text boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-10, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    // 设置myLabel的尺寸
    self.myLabel.frame = CGRectMake(5, 333*ALL_EDITION_HEIGHT+5, SCREEN_WIDTH-10, rect.size.height);
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    self.contentView.backgroundColor = [UIColor clearColor];
}
#pragma mark - Method setModel
- (void)setModel:(JSMDreamCitySpecialDetailModel *)model {
    if (_model != model) {
        _model = model;
    }
    [self.myImageView sd_setImageWithURL:[NSURL URLWithString:model.imageUrl] placeholderImage:[UIImage imageNamed:PLACE_HOLDER_IMAGE]];
    self.myLabel.text = model.imageDesc;
}
@end
